﻿using System;

namespace DAPNet
{
    public class Sample
    {
        public const double MinValue = -1;

        public const double BaseValue = 0;

        public const double MaxValue = 1;

        private double value;


        public Sample() : this(BaseValue)
        {
        }

        public Sample(double value)
        {
            if (!IsValidValue(value))
            {
                //TODO: EXCEPTION CONSIDERATION.
                throw new ArgumentException();
            }

            this.value = value;
        }

        public double Value
        {
            get 
            { 
                return value; 
            }
            set 
            { 
                this.value = value; 
            }
        }

        public static bool IsValidValue(double value)
        {
            return (value >= MinValue && value <= MaxValue);
        }

        public void SetTrimmedValue(double value)
        {
            if (value < MinValue)
            {
                this.value = MinValue;
            }
            else if (value > MaxValue)
            {
                this.value = MaxValue;
            }
            else
            {
                this.value = value;
            }       }

        public Sample Clone()
        {
            return new Sample(value);
        }
    }
}
